 ;
 (function() {
 	/*
 	 * 设置调查项目期数
 	 * */
 	$.ajax({
 		type: "get",
 		url: "GetPeriod",
 		async: true,
 		success: function(data) {
 			$(".No").find("p").append("<strong>编号：</strong>HX-YNKM-QR-7.5-" + data.period);
 		}
 	});

 	/* 
 	 * 设置选择的分数
 	 * */
 	$('table').on("click", ":radio", function() {
 		var scFiCount = 0,
 			scFoCount = 0,
 			scThCount = 0,
 			scTwoCount = 0,
 			scOneCount = 0;
 		var scFi = 0,
 			scFo = 0,
 			scTh = 0,
 			scTwo = 0,
 			scOne = 0;

 		var _clickthis_ = this;
 		var clickedScore = $(_clickthis_).val();
 		$(_clickthis_).parents("tr").find("input[name=score]").val(clickedScore);

 		//将标记为没有选择报错的背景颜色去掉
 		$(_clickthis_).parents("tr").css("background-color", "#FCFCFC");

 		$('.col5').each(function() {
 			var _this_ = this;
 			if(_this_.checked === true) scFiCount++;
 		});

 		$('.col4').each(function() {
 			var _this_ = this;
 			if(_this_.checked === true) scFo++;
 		});

 		$('.col3').each(function() {
 			var _this_ = this;
 			if(_this_.checked === true) scThCount++;
 		});

 		$('.col2').each(function() {
 			var _this_ = this;
 			if(_this_.checked === true) scTwoCount++;
 		});

 		$('.col1').each(function() {
 			var _this_ = this;
 			if(_this_.checked === true) scOneCount++;
 		});

 		scFi = 5 * scFiCount;
 		scFo = 4 * scFoCount;
 		scTh = 3 * scThCount;
 		scTwo = 2 * scTwoCount;
 		scOne = 1 * scOneCount;

 		$('.score5').html(scFi);
 		$('.score4').html(scFo);
 		$('.score3').html(scTh);
 		$('.score2').html(scTwo);
 		$('.score1').html(scOne);
 		$('.scoretotal').html(scFi + scFo + scTh + scTwo + scOne);
 	});

 	/*
 	 * 生成表格评价项目
 	 */
 	$.ajax({
 		type: "get",
 		url: "GetSurCont",
 		async: true,
 		success: function(data) {
 			var num = 0;
 			$.each(data, function(index, val) {
 				var contlen = val.cont.length + 1;
 				$(".total").before("<tr><td rowspan='" + contlen + "'" + " class='highlight'>" + val.id + "</td><td rowspan='" + contlen + "'" + " class='highlight'>" + val.name + "</td></tr>");
 				$.each(val.cont, function(index1, contVal) {
 					num++;
 					$(".total").before("<tr><td>" + contVal.content +
 						"<input type='hidden' name='content_id' value='" + contVal.id + "'/>" +
 						"<input type='hidden' name='score' />" +
 						"</td><td><input type='radio' class='col5'" + " name='line" + num + "' value='5'></td>" +
 						"</td><td><input type='radio' class='col4'" + " name='line" + num + "' value='4'></td>" +
 						"</td><td><input type='radio' class='col3'" + " name='line" + num + "' value='3'></td>" +
 						"</td><td><input type='radio' class='col2'" + " name='line" + num + "' value='2'></td>" +
 						"</td><td><input type='radio' class='col1'" + " name='line" + num + "' value='1'></td></tr>");
 				});
 			});
 		}
 	});

 	/*
 	 * 设置专业并且获取对应课程
 	 */
 	$.ajax({
 		type: "get",
 		url: "GetMajor",
 		async: true,
 		success: function(data) {
 			$(".appendli1").append('<li class="majorClick"><a href="javascript:getCourse();">' + data.name + '</a></li>');
 		}
 	});

 	//将选择的专业复制到text框里
 	$("body").on("click", ".majorClick", function() {
 		var inText = document.getElementById("text1");
 		inText.value = $(".majorClick").find("a").html();
 		if($(".err")) {
 			$(".err").remove();
 		}
 	});

 	//设置课程全选
 	$('.appendli2').on("click", "input[name=allSelect1]", function() {
 		if($('input[name=allSelect1]').prop("checked") === true) {
 			$('input[name=checkCourse]').each(function() {
 				var _this_ = this;
 				$(_this_).prop("checked", true);
 			});
 		} else {
 			$('input[name=checkCourse]').each(function() {
 				var _this_ = this;
 				$(_this_).prop("checked", false);
 			});
 		}
 	});

 	//将选择的课程复制到text框里并获取课程对应的教师
 	$('.appendli2').on("click", "input[name=btn1]", function() {
 		var str = "";
 		$('input[name=checkCourse]').each(function() {
 			var _this_ = this;
 			if($(_this_).prop("checked") === true) {
 				var textVal = $(_this_).parent().text();
 				str += textVal + ","
 			}
 		});
 		str = str.substring(0, (str.length - 1));
 		$('#text2').prop("value", str);

 		if($(".err")) {
 			$(".err").remove();
 		}
 		//获取教师
 		getTeacher();
 	});

 	/*
 	 * 将选择的教师复制到text框里并提交教师姓名
 	 */
 	$('.appendli3').on("click", "input[name=btn2]", function() {
 		var str = "";
 		$('input[name=chTeacher]').each(function() {
 			var _this_ = this;
 			if($(_this_).prop("checked") === true) {
 				var textVal = $(_this_).parent().text();
 				str += textVal + ","
 			}
 		});
 		str = str.substring(0, (str.length - 1));
 		$('#text3').prop("value", str);
 		if($(".err")) {
 			$(".err").remove();
 		}
 		SetTeacher();
 	});

 	$('.appendli3').on("click", "input[name=allSelect2]", function() {
 		if($('input[name=allSelect2]').prop("checked") === true) {
 			$('input[name=chTeacher]').each(function() {
 				var _this_ = this;
 				$(_this_).prop("checked", true);
 			});
 		} else {
 			$('input[name=chTeacher]').each(function() {
 				var _this_ = this;
 				$(_this_).prop("checked", false);
 			});
 		}
 	});

 })();

 //获取专业对应的课程
 function getCourse() {
 	var ali = $(".appendli2").find("li");
 	if(ali.length != 0) {
 		$(".appendli2").empty();
 	}
 	$.ajax({
 		type: "get",
 		url: "GetCourse",
 		async: true,
 		data: $("#form1").serialize(),
 		success: function(data) {
 			$('.appendli2').append('<input type="checkbox" name="allSelect1">全选</input>');
 			$.each(data, function(index, val) {
 				$(".appendli2").append('<li><input type="checkbox" name="checkCourse" value="' + index + '">' + val.name + '</input></li>');
 			});
 			$('.appendli2').append('<input type="button" name="btn1" value="确  定"></button>');
 		}
 	});
 }

 //获取课程对应的教师
 function getTeacher() {
 	var ali = $(".appendli3").find("li");
 	if(ali.length != 0) {
 		$(".appendli3").empty();
 	};
 	$.ajax({
 		type: "get",
 		url: "GetTeacher",
 		async: true,
 		data: $("#form2").serialize(),
 		success: function(data) {
 			$('.appendli3').append('<input type="checkbox" name="allSelect2">全选</input>');
 			$.each(data, function(index, val) {
 				$(".appendli3").append('<li><input type="checkbox" name="chTeacher" value="' + index + '">' + val.name + '</input></li>');
 			});
 			$('.appendli3').append('<input type="button" name="btn2" value="确  定"></button>');
 		}
 	});
 }

 //提交评价教师姓名
 function SetTeacher() {
 	$.ajax({
 		type: "get",
 		url: "SetTeacher",
 		async: true,
 		data: $("#form3").serialize()
 	});
 }

 /*
  * 提交表格评分radio和建议textarea
  * 
  */
 function subTable() {
 	var isSub = true;
 	/*
 	 *如果没有选择专业被弹出提示框
 	 * */
 	if($("input[name=majorname]").val() == "") {
 		alert("评分专业不能为空！请选择专业");
 		$("button[name=butt1]").after(" <img class='err' src='img/cuowu.png'/> ");
 		return false;
 	}
 	/*
 	 *如果没有选择课程被弹出提示框
 	 * */
 	if($("input[name=coursename]").val() == "") {
 		alert("评分课程不能为空！请选择课程");
 		$("button[name=butt2]").after(" <img class='err' src='img/cuowu.png'/> ");
 		return false;
 	}
 	/*
 	 *如果没有选择教师被弹出提示框
 	 * */
 	if($("input[name=teachername]").val() == "") {
 		alert("评分教师不能为空！请选择教师");
 		$("button[name=butt3]").after(" <img class='err' src='img/cuowu.png'/> ");
 		return false;
 	}
 	/*
 	 *如果没有选择评分则提示没有对该项目进行评分
 	 * */
 	$("input[name=score]").each(function() {
 		var _this_ = this;
 		if($(_this_).val() == "") {
 			$(_this_).parents("tr").css("background-color", "#FFC125");
 			isSub = false;
 		}
 	});

    /*
 	 *如果有调查项目没有进行评分，则将isSub标记为false
 	 * */
 	if(!isSub) {
 		alert("有项目没有评分，全部评分完成后才可以提交！");
 	}

    /*
 	 *如果所有内容都提交了，则进行评分提交
 	 * */
 	if(isSub) {
 		$.ajax({
 			type: "get",
 			url: "SetSurDetail",
 			async: true,
 			data: $('form[name=tableForm]').serialize(),
 			dataType: "text",
 			success: function(data) {
 				if(data == "successful") {
 					window.location.href = "finish.html";
 				} else if(data == "voted") {
 					window.location.href = "voted.html";
 				} else {
 					window.location.href = "fail.html";
 				}
 			}
 		});
 	}
 	isSub = true;
 }